package voldemort.store.cachestore;

import voldemort.store.cachestore.impl.Purge;
import voldemort.utils.ByteArray;

import static voldemort.store.cachestore.BlockUtil.*;

/**
 * Created by IntelliJ IDEA.
 * User: mhsieh
 * Date: 3/14/11
 * Time: 10:04 AM
 * To change this template use File | Settings | File Templates.
 */
public class PurgeByKey implements Purge {
    private int base = 100;

    public  PurgeByKey() {
        super();
    }

    public void setBase(int base) {
        this.base = base;
    }


    @Override
    public boolean isDelete(byte[] datas, Key key) {
        if ( key.getType() == KeyType.LONG ) {
            if ( (Long) key.getKey() % base == 0 ) return true;
        }
        else if ( key.getType() == KeyType.BARRAY ) {
            byte[] data = ((ByteArray) key.getKey()).get();
            long k = Bits.getLong(data, 0);
            if ( k % base == 0 ) return true;
        }
        return false;
    }
}
